<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>AdminLTE 2 | Dashboard</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">


    <!-- Google Font -->
    <link rel="stylesheet"
          href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">

    <!-- Bootstrap 3.3.7 -->
    <link rel="stylesheet" th:href="@{/bower_components/bootstrap/dist/css/bootstrap.min.css}" type="text/css">

    <!-- Font Awesome -->
    <link rel="stylesheet" th:href="@{/bower_components/font-awesome/css/font-awesome.min.css}" type="text/css">
    <!-- Ionicons -->
    <link rel="stylesheet" th:href="@{/bower_components/Ionicons/css/ionicons.min.css}" type="text/css">
    <!-- Theme style -->
    <link rel="stylesheet" th:href="@{/dist/css/AdminLTE.min.css}" type="text/css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" th:href="@{/dist/css/skins/_all-skins.min.css}" type="text/css">
    <!-- Morris chart -->
    <link rel="stylesheet" th:href="@{/bower_components/morris.js/morris.css}" type="text/css">
    <!-- jvectormap -->
    <link rel="stylesheet" th:href="@{/bower_components/jvectormap/jquery-jvectormap.css}" type="text/css">
    <!-- Date Picker -->
    <link rel="stylesheet" th:href="@{/bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css}"
          type="text/css">
    <!-- Daterange picker -->
    <link rel="stylesheet" th:href="@{/bower_components/bootstrap-daterangepicker/daterangepicker.css}" type="text/css">
    <!-- bootstrap wysihtml5 - text editor -->
    <link rel="stylesheet" th:href="@{/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css}" type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- Google Font -->
    <link rel="stylesheet"
          href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>
<body class="hold-transition skin-blue sidebar-mini fixed">
<div class="wrapper">

    <header class="main-header">
        <div th:include="common/head :: head"></div>
    </header>
    <!-- Left side column. contains the logo and sidebar -->
    <aside class="main-sidebar">
        <!-- sidebar: style can be found in sidebar.less -->
        <section class="sidebar">

            <div th:include="common/left :: left"></div>
        </section>
        <!-- /.sidebar -->
    </aside>
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">

        <h2 class="profile-username text-center">增加课程章节</h2>

        <!-- Main content -->
        <section class="content">
            <!-- /.row -->
            <div class="row">
                <div class="col-md-12 col-sm-12 col-xs-12">
                    <div class="info-box">
                        <span class="info-box-icon "><img th:src="${course.getImgpath()}"></span>
                        <div class="info-box-content">
                            <span class="info-box-number"><h3 th:text="'课程名：'+${course.coursename}"></h3></span>
                            <span class="info-box-number"><h4 th:text="'创建时间：'+${course.createtime}"></h4></span>
                        </div>
                        <!-- /.info-box-content -->
                    </div>
                    <!-- /.info-box -->
                    <!-- Default box -->
                    <button class="btn btn-primary btn-block" onclick="addchapter()">增加章节</button>
                    <form  action="/savechaptername" method="post" id="myform">
                        <p></p><p></p>
                        <input type="hidden" name="courseid" th:value="${course.getCourseid()}">
                        <div class="box">
                            <div class="box-header with-border">
                                <h3 class="box-title">请输入每章章节标题(从上往下依次是第1章->第n章)</h3>
                                <div class="box-tools pull-right">
                                    <button type="button" class="btn btn-box-tool" data-widget="remove"
                                            data-toggle="tooltip" title="Remove" >
                                        <i class="fa fa-times"></i></button>
                                </div>
                            </div>
                            <div class="box-body">
                                <div class="form-group">
                                    <label  class="col-sm-2 control-label">章节名：</label>
                                    <div class="col-sm-10">
                                        <input type="text" class="form-control"  placeholder="请输入章节名" name="chaptername"
                                               ><span></span>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!-- /.box -->
                            <button type="submit" class="btn btn-primary btn-block" th:id="myform1" onclick="save()">提交保存</button>
                    </form>
                </div>
                <!--row end-->
                <!-- Default box -->
            </div>
        </section>
        <!-- /.content -->


    </div>
    <!-- /.content-wrapper -->
    <footer class="main-footer">
        <div th:include="common/footer :: footer"></div>
    </footer>
    <!-- Add the sidebar's background. This div must be placed
         immediately after the control sidebar -->
    <div class="control-sidebar-bg"></div>
</div>
<!-- ./wrapper -->

<!-- jQuery 3 -->
<script th:src="@{/bower_components/jquery/dist/jquery.min.js}" type="text/javascript"></script>
<!-- jQuery UI 1.11.4 -->
<script th:src="@{/bower_components/jquery-ui/jquery-ui.min.js}" type="text/javascript"></script>
<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
<script>
    $.widget.bridge('uibutton', $.ui.button);
</script>
<!-- Bootstrap 3.3.7 -->
<script th:src="@{/bower_components/bootstrap/dist/js/bootstrap.min.js}" type="text/javascript"></script>
<!-- Morris.js charts -->
<script th:src="@{/bower_components/raphael/raphael.min.js}" type="text/javascript"></script>
<script th:src="@{/bower_components/morris.js/morris.min.js}" type="text/javascript"></script>
<!-- Sparkline -->
<script th:src="@{/bower_components/jquery-sparkline/dist/jquery.sparkline.min.js}" type="text/javascript"></script>
<!-- jvectormap -->
<script th:src="@{/plugins/jvectormap/jquery-jvectormap-1.2.2.min.js}" type="text/javascript"></script>
<script th:src="@{/plugins/jvectormap/jquery-jvectormap-world-mill-en.js}" type="text/javascript"></script>
<!-- jQuery Knob Chart -->
<script th:src="@{/bower_components/jquery-knob/dist/jquery.knob.min.js}" type="text/javascript"></script>
<!-- daterangepicker -->
<script th:src="@{/bower_components/moment/min/moment.min.js}" type="text/javascript"></script>
<script th:src="@{/bower_components/bootstrap-daterangepicker/daterangepicker.js}" type="text/javascript"></script>
<!-- datepicker -->
<script th:src="@{/bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js}"
        type="text/javascript"></script>
<!-- Bootstrap WYSIHTML5 -->
<script th:src="@{/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js}" type="text/javascript"></script>
<!-- Slimscroll -->
<script th:src="@{/bower_components/jquery-slimscroll/jquery.slimscroll.min.js}" type="text/javascript"></script>
<!-- FastClick -->
<script th:src="@{/bower_components/fastclick/lib/fastclick.js}" type="text/javascript"></script>
<!-- AdminLTE App -->
<script th:src="@{/dist/js/adminlte.min.js}" type="text/javascript"></script>
<!-- AdminLTE dashboard demo (This is only for demo purposes) -->
<script th:src="@{/dist/js/pages/dashboard.js}" type="text/javascript"></script>
<!-- AdminLTE for demo purposes -->
<script th:src="@{/dist/js/demo.js}" type="text/javascript"></script>


<script type="text/javascript">
    $(function () {
        $('.sidebar-menu li:not(.treeview) > a').on('click', function () {
            console.log(this.href);
            var $parent = $(this).parent().addClass('active');
            $parent.siblings('.treeview.active').find('> a').trigger('click');
            $parent.siblings().removeClass('active').find('li').removeClass('active');
        });
        $('.sidebar-menu a').each(function () {
            if (this.href === window.location.href) {
                $(this).parent().addClass('active')
                    .closest('.treeview-menu').addClass('.menu-open')
                    .closest('.treeview').addClass('active');
            }
        });
    });
</script>
<script type="text/javascript">
    function addchapter() {
        $("#myform1").before("<div class=\"box\">\n" +
            "                            <div class=\"box-header with-border\">\n" +
            "                                <h3 class=\"box-title\">请输入每章章节标题(从上往下依次是第1章->第n章)</h3>\n" +
            "\n" +
            "                                <div class=\"box-tools pull-right\">\n" +
            "                                    <button type=\"button\" class=\"btn btn-box-tool\" data-widget=\"remove\"\n" +
            "                                            data-toggle=\"tooltip\" title=\"Remove\" onclick=\"remove(this)\">\n" +
            "                                        <i class=\"fa fa-times\"></i></button>\n" +
            "                                </div>\n" +
            "                            </div>\n" +
            "                            <div class=\"box-body\">\n" +
            "                                <div class=\"form-group\">\n" +
            "                                    <label  class=\"col-sm-2 control-label\">章节名：</label>\n" +
            "\n" +
            "                                    <div class=\"col-sm-10\">\n" +
            "                                        <input type=\"text\" class=\"form-control\" name=\"chaptername\"  placeholder=\"请输入章节名\"\n" +
            "                                               >\n" +
            "                                    <span></span></div>\n" +
            "                                </div>\n" +
            "                            </div>\n" +
            "                        </div>");
    }

    function remove(a) {
        $(a).parents(".box").fadeTo("slow", 0.01, function(){
            $(this).slideUp("slow", function() {
                $(this).remove();
            });
        });
    }


    $(document).on("blur","[name=chaptername]",function () {
        if ($(this).val() != "") {
            $(this).next().text("");
        } else {
            $(this).next().text("不能为空").css("color", "red");
        }
    });

    //密码验证
    $("[name=chaptername]").blur(function () {
        if ($(this).val() != "") {
            $(this).next().text("");
        } else {
            $(this).next().text("不能为空").css("color", "red");
        }
    });



    //保存相同name的值阻断提交
    function save() {
        var i=0;
        $("input[name='chaptername']").each(function(){
            if($(this).val()==""){
                i=i+1;
            }
        });
        if (i>0) {
            $("#myform").bind("submit", (function (e) {
                e.preventDefault();
            }));
            confirm("输入的信息有误，请重新检查");
        } else {
            var r=confirm("确认保存？");
            if(r==true){
                $("#myform").unbind("submit");
            }
        }
    }
</script>
</body>
</html>
